<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" size="mini" class="form-filter">
      <el-form-item label="">
        <el-input v-model="formItem.s_name" clearable placeholder="请输入名称..." @keyup.enter.native="search" @change="onMixedInputChange" />
      </el-form-item>
      <el-form-item label="">
        <el-input v-model="formItem.s_code" clearable placeholder="请输入编码..." @keyup.enter.native="search" @change="onMixedInputChange" />
      </el-form-item>
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
        <!-- <el-button plain icon="el-icon-refresh-left" @click="reset">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_code: ''
}

export default {
  name: 'UsersTableFilter',
  data() {
    return {
      formItem: { ...formItem }
    }
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      this.$parent.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = { ...formItem }
      this.search()
    },
    onChange: function(val) {
      this.$parent.onResize()
    },
    // 复合型输入框 input 值改变事件
    onMixedInputChange(value) {
      if (value === '') {
        this.search()
      }
    }
  }
}
</script>
